package com.qfedu.config;

import com.qfedu.constant.*;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置静态文件
 */
@Configuration
public class MyPicConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) { // windos系统
            registry.addResourceHandler("/img/songPic/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_WIN_PATH + "\\img\\songPic\\");
            registry.addResourceHandler("/song/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_WIN_PATH + "\\song\\");
            registry.addResourceHandler("/img/singerPic/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_WIN_PATH + "\\img\\singerPic\\");
            registry.addResourceHandler("/img/songListPic/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_WIN_PATH + "\\img\\songListPic\\");
        } else { // MAC、Linux系统
            registry.addResourceHandler("/img/songPic/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_MAC_PATH + "/img/songPic/");
            registry.addResourceHandler("/song/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_MAC_PATH + "/song/");
            registry.addResourceHandler("/img/singerPic/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_MAC_PATH + "/img/singerPic/");
            registry.addResourceHandler("/img/songListPic/**")
                    .addResourceLocations("file:" + Constants.RESOURCE_MAC_PATH + "/img/songListPic/");
        }
    }
}